package com.jsbb.service.sys;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jsbb.dto.sys.SysLogQueryDto;
import com.jsbb.mapper.sys.SysLogMapper;
import com.jsbb.model.sys.SysLog;
import com.jsbb.vo.PageVo;
import com.jsbb.vo.sys.SysLogVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统日志Service
 *
 * @author w
 * @date 2021-03-08
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    public PageVo<SysLogVo> list(SysLogQueryDto queryDto) {
        Page page = PageHelper.startPage(queryDto.getPageNo(), queryDto.getPageSize());
        List<SysLog> list = sysLogMapper.selectByCondition(queryDto);
        List<SysLogVo> logVoList = new ArrayList<>();
        for (SysLog sysLog : list) {
            SysLogVo logVo = new SysLogVo();
            BeanUtils.copyProperties(sysLog, logVo);
            logVoList.add(logVo);
        }
        return new PageVo((int) page.getTotal(), logVoList);
    }
}
